#include('./header.html',{active:'settings', title:'系统设置'})
<link href="/static/admin/plugins/toggles/toggles.css" rel="stylesheet">
<div class="row">

    <div class="col-sm-12">
        <h4 class="page-title">系统设置</h4>
    </div>

    <div class="col-md-6">
        <div class="panel panel-color panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">全局设置</h3>
            </div>
            <div class="panel-body">
                <form class="form-horizontal" role="form" id="global-form">
                    <div class="form-group">
                        <label class="col-md-3 control-label">站点名称</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="site_title" placeholder="站点名称"
                                   value="${options.site_title}" required aria-required="true"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">站点描述</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="site_description" placeholder="站点描述"
                                   value="${options.site_description}" required aria-required="true"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">站点关键词</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="site_keywords" placeholder="站点关键词"
                                   value="${options.site_keywords}" required aria-required="true"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">博客主题</label>
                        <div class="col-md-9">
                            <select name="site_theme" class="form-control">
                                <option value="default" #if(options.site_theme=='default') selected #end>默认主题</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">允许重新安装</label>
                        <div class="col-md-9">
                            <div class="toggle toggle-success allow-${options.allow_install}"
                                 onclick="allow_reinstall(this);"></div>
                        </div>
                    </div>
                    <input type="hidden" name="allow_install" id="allow_install"/>
                    <div class="clearfix pull-right">
                        <button type="button" class="btn btn-primary waves-effect waves-light" onclick="saveSetting()">
                            保存设置
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="panel panel-color panel-inverse">
            <div class="panel-heading">
                <h3 class="panel-title">个性化设置</h3>
            </div>
            <div class="panel-body">
                <form id="indivi-form" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-md-3 control-label">微博账号</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="social_weibo" value="${options.social_weibo}"
                                   placeholder="微博账号，不输入则不显示">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">知乎账号</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="social_zhihu" value="${options.social_zhihu}"
                                   placeholder="知乎账号，不输入则不显示">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">Github账号</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="social_github"
                                   value="${options.social_github}" placeholder="Github账号，不输入则不显示">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">Twitter账号</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="social_twitter"
                                   value="${options.social_twitter}" placeholder="Twitter账号，不输入则不显示">
                        </div>
                    </div>
                    <div class="clearfix pull-right">
                        <button type="button" class="btn btn-inverse waves-effect waves-light"
                                onclick="saveIndiviSetting()">
                            保存设置
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="clearfix"></div>

    <div class="col-md-6">
        <div class="panel panel-color panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">系统备份（备份文件包含附件和主题）</h3>
            </div>
            <div class="panel-body">
                <form id="backupForm" class="form-inline" role="form">
                    <!--<div class="form-group">
                        <label class="sr-only">备份格式</label>
                        <input name="url" class="form-control" placeholder="请输入备份文件格式，如yyyy-MM-dd" required="" aria-required="true" type="url">
                    </div>-->
                    <div class="form-group col-md-6">
                        <input id="backup_dir" style="width: 100%;" class="form-control" placeholder="请输入备份存放的磁盘路径" required="" aria-required="true" type="text">
                    </div>

                    <button type="button" class="btn btn-success waves-effect waves-light m-l-10" onclick="backup('attach');">备份文件</button>
                    <button type="button" class="btn btn-danger waves-effect waves-light m-l-10" onclick="backup('db')">导出数据库SQL</button>
                </form>
            </div>
        </div>
    </div>

</div>
#include('./footer.html')
<script src="//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js"></script>
<script type="text/javascript">

    /**
     * 保存全局设置
     */
    function saveSetting() {
        var param = $('#global-form').serialize();
        $.post('/admin/setting', param, function (result) {
            if (result && result.success) {
                swal('提示信息', '保存成功', 'success');
            } else {
                swal("提示消息", result.msg, 'error');
            }
        });
    }

    /**
     * 保存个性化设置
     */
    function saveIndiviSetting() {
        var param = $('#indivi-form').serialize();
        $.post('/admin/setting', param, function (result) {
            if (result && result.success) {
                swal('提示信息', '保存成功', 'success');
            } else {
                swal("提示消息", result.msg, 'error');
            }
        });
    }
    /**
     * 设置是否允许重新安装
     */
    function allow_reinstall(obj) {
        var this_ = $(obj);
        var on = this_.find('.toggle-on.active').length;
        var off = this_.find('.toggle-off.active').length;
        if (on == 1) {
            $('#allow_install').val(0);
        }
        if (off == 1) {
            $('#allow_install').val(1);
        }
    }

    /**
     * 系统备份
     * @param type
     */
    function backup(type) {
        var param = {
            bk_type: type,
            bk_path: $('#backup_dir').val()
        };
        $.post('/admin/backup', param, function (result) {
            result = eval(result);
            if (result && result.success) {
                if(result.payload && result.payload.attach_path){
                    swal('备份成功', '您的附件备份在 <mark>'+ result.payload.attach_path +'</mark><br/><br/>' +
                        '主题备份存储在 <mark>'+ result.payload.theme_path +'</mark>', 'success');
                    $('#backup_dir').val('');
                }
                if(result.payload.sql_path){
                   window.location.href = '/upload/' + result.payload.sql_path;
                }
            } else {
                swal("提示消息", result.msg, 'error');
            }
        });
    }


    $('.allow-1').toggles({
        on: true,
        text: {
            on: '开启',
            off: '关闭'
        }
    });
    $('.allow-0').toggles({
        off: true,
        text: {
            on: '开启',
            off: '关闭'
        }
    });
</script>
</body>
</html>